import {post, get, put} from '@/api/httphelper.js'
import {ElMessage} from "element-plus";

function showMessageError(type, message) {
    ElMessage({
        message: message,
        //warning 、error、success
        type: type,
    });
}

export function loginApi(userName, passWord) {
    return post("/pagehelper/user/login",
        {userName: userName, passWord: passWord}
    )
}

export function loginOutApi() {
    return get("/pagehelper/user/loginout",
        {}
    )
}

export function selectPage(pageSize, pageNum, username) {
    return get("/pagehelper/user/page",
        {
            pageNum: pageNum, pageSize: pageSize, username: username
        }
    )
}

// 同步方法
export async function selectPageSyn(pageSize, pageNum, username) {
    try {
        const response = await get("/pagehelper/user/page",
            {
                pageNum: pageNum, pageSize: pageSize, username: username
            }
        )
        return response;
    } catch (e) {
        console.error(e);
    }
}

export function sexTypeApi() {
    return get("/pagehelper/user/sexType",
        {}
    )
}

export function updateUserApi(user) {
    return post("/pagehelper/user/update",
        user
    )
}

export function addUserApi(user) {
    return post("/pagehelper/user/insert",
        user
    )
}

export function deleteUserApi(userId) {
    return get("/pagehelper/user/delete",
        {
            userId: userId
        }
    )
}
